// createRouter：创建路由实例
// createWebHistory：创建基于 HTML5 history.pushState API 的路由
import { createRouter, createWebHistory } from 'vue-router'
import Login from '@/views/login/Index.vue'
import Layout from '@/views/layout/Index.vue'
import Home from '@/views/home/Index.vue'
import Category from '@/views/category/Index.vue'
import SubCategory from '@/views/subCategory/Index.vue'
import Detail from '@/views/detail/Index.vue'
import CartList from '@/views/cartList/Index.vue'
import Checkout from '@/views/checkout/Index.vue'
import Pay from '@/views/pay/Index.vue'
import PayBack from '@/views/pay/PayBack.vue'
import Member from '@/views/member/Index.vue'
import UserInfo from '@/views/member/components/UserInfo.vue'
import UserOrder from '@/views/member/components/UserOrder.vue'
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  // 路由配置：path 为路由路径，component 为路由组件
  routes: [
    {
      path: '/',
      component: Layout,
      children: [
        {
          path: '',
          component: Home,
        },
        {
          path: 'category/:id',
          component: Category,
        },
        {
          path: 'category/sub/:id',
          component: SubCategory,
        },
        {
          path: 'detail/:id',
          component: Detail,
        },
        {
          path: 'cartList',
          component: CartList,
        },
        {
          path: 'checkout',
          component: Checkout,
        },
        {
          path: 'pay',
          component: Pay,
        },
        {
          path: 'paycallback',
          component: PayBack,
        },
        {
          path: 'member',
          component: Member,
          children: [
            {
              path: '',
              component: UserInfo,
            },
            {
              path: 'order',
              component: UserOrder,
            },
          ],
        },
      ],
    },
    {
      path: '/login',
      component: Login,
    },
  ],
  // 路由滚动行为定制
  scrollBehavior() {
    return {
      left: 0,
      top: 0,
    }
  },
})

export default router
